output_dir=output   # 训练目录
dataset_dir=quiz_w8_data # 数据集目录


train_dir=$output_dir/train
checkpoint_dir=$train_dir
eval_dir=$output_dir/eval

# config文件
config=ssd_mobilenet_v1_quiz_w8_data.config
# pipeline_config_path=output/ssd_mobilenet_v1_quiz_w8_data.config
pipeline_config_path=$output_dir/$config

cp $dataset_dir/$config $pipeline_config_path


# for循环中的代码执行5此，这里的左右边界都包含，也就是一共训练500个step，每100step验证一次
for i in {0..4}
do
    echo "############" $i "runnning #################"
    last=$[$i*100]
    current=$[($i+1)*100]
    sed -i "s/^  num_steps: $last$/  num_steps: $current/g" $pipeline_config_path  # 通过num_steps控制一次训练最多100step

    echo "############" $i "training #################"
    python object_detection/legacy/train.py --train_dir=$train_dir --pipeline_config_path=$pipeline_config_path

    echo "############" $i "evaluating, this takes a long while #################"
    python object_detection/legacy/eval.py --checkpoint_dir=$checkpoint_dir --eval_dir=$eval_dir --pipeline_config_path=$pipeline_config_path
done


# 导出模型
python object_detection/export_inference_graph.py --input_type image_tensor --pipeline_config_path $pipeline_config_path --trained_checkpoint_prefix $train_dir/model.ckpt-$current  --output_directory $output_dir/exported_graphs
